use ClientPlatform

var regExp = /(.+\w+)( - | -|- )(Weighted Score|Answer Category|Impact Answer Category|Risk Answer Category|Weight|Score)/;

function updateCriteriaName(collection) {
    collection
        .find({Name: regExp})
        .snapshot()
        .forEach(function (item) {
            print(item.Name);
            item.Name = item.Name.replace(regExp, '$1-$3');
            print(item.Name);
            collection.save(item);
        });
}

updateCriteriaName(db.FilterCriteria);
updateCriteriaName(db.TemplateCriteria);
updateCriteriaName(db.OldTemplateCriteria);


var level2Id = db.CriteriaLevel2.findOne({ Name: 'Others' })._id;
db.CriteriaLevel3.update({ Name: 'SPL Code' }, { $set: { CriteriaLevel2Id: level2Id } });

db.getCollection('CriteriaLevel3').update({ Name: 'Market Capitalization' }, { $set: { Name: 'Market cap. (mln. USD)' } })
db.getCollection('FilterCriteria').update({ Name: 'Market Capitalization' }, { $set: { Name: 'Market cap. (mln. USD)' } }, { multi: true })
db.getCollection('TemplateCriteria').update({ Name: 'Market Capitalization' }, { $set: { Name: 'Market cap. (mln. USD)' } })
db.getCollection('OldTemplateCriteria').update({ Name: 'Market Capitalization' }, { $set: { Name: 'Market cap. (mln. USD)' } })
